package com.example.design.ddd.practice.domain.orgmng.orgservice;

import com.example.design.ddd.practice.common.framework.exception.BusinessException;
import com.example.design.ddd.practice.domain.empmng.repository.EmpRepository;
import com.example.design.ddd.practice.domain.empmng.entity.EmpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrgLeaderValidator {
    @Autowired
    EmpRepository empRepository;

    // 组织负责人可以空缺，如果有的话，的必须是一个在职员工（含试用期）
    public void leaderShouldBeEffective(Long tenant, Long leader) {
        if (leader != null
                && !empRepository.existsByIdAndStatus(tenant, leader
                , EmpStatus.REGULAR, EmpStatus.PROBATION)) {
            throw new BusinessException("组织负责人(id='" + leader + "')不是在职员工！");
        }
    }
}
